package com.qianyu.project.mapper.provider.sy;

import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.jdbc.SQL;
import org.springframework.util.StringUtils;

import java.util.Map;

public class ContractChangeProvider {

    public String getList(IPage page, Map<String, String> params){
        return new SQL(){
            {
                SELECT("c.*, p.project_name, i.contract_name ");
                FROM("contract_change c, project_info p, income_contract i");
                WHERE("c.pid = p.id and c.ctr_id = i.id");
                if(StringUtils.hasLength(params.get("id"))){
                    WHERE(" c.id = #{params.id}");
                }
                if(StringUtils.hasLength(params.get("changeName"))){
                    WHERE(" c.change_name like '%${params.changeName}%'");
                }
                if(StringUtils.hasLength(params.get("pid"))){
                    WHERE(" c.pid = #{params.pid}");
                }
                if (StringUtils.hasLength(params.get("approveStatus"))){
                    WHERE(" c.approve_status = #{params.approveStatus}");
                }
                if (StringUtils.hasLength(params.get("ctrId"))){
                    WHERE(" c.ctr_id = #{params.ctrId}");
                }
                if (StringUtils.hasLength(params.get("handlerId"))){
                    WHERE(" c.handler_id like '%${params.handlerId}%'");
                }
                if(StringUtils.hasLength(params.get("applyDate1")) && StringUtils.hasLength(params.get("applyDate2"))){
                    WHERE(" c.apply_date >= '${params.applyDate1}' and c.apply_date <= '${params.applyDate2}'");
                }
            }
        }.toString();
    }

    public String getOne(String id) {
        return new SQL() {
            {
                SELECT("c.*, p.project_name, i.contract_name ");
                FROM("contract_change c, project_info p, income_contract i");
                WHERE("c.pid = p.id and c.ctr_id = i.id and c.id = #{id}");
            }
        }.toString();
    }
}
